<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/index.css">
    <script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/layui-post.js"></script>
    <script type="text/javascript" src="/js/xcity.js"></script>
    <script type="text/javascript" src="/verify.js"></script>
</head>
<style type="text/css">
    .layui-col-md6{margin-bottom: 10px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form layui-form-pane" lay-filter="editForm" id="edit">
            <div class="layui-card-body ">
                <div class="layui-tab layui-tab-card">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">团购商品</label>
                            <div class="layui-input-block">
                                <select name="goodsId" id="goodsId" lay-filter="goodsIdFilter" lay-verify="required" lay-search><option value="">请选择团购商品</option></select>
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">活动名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="actiName" autocomplete="off" placeholder="请输入活动名称" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">活动价格</label>
                            <div class="layui-input-block">
                                <input type="number" name="actiPrice" autocomplete="off" placeholder="请输入活动价格" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">成团人数</label>
                            <div class="layui-input-block">
                                <input type="number" name="groupSize" autocomplete="off" lay-verify="required|numminmax" lay-title="成团人数" lay-min="2" lay-max="100" placeholder="请输入成团人数" value="2" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">开始时间</label>
                            <div class="layui-input-block">
                                <input class="layui-input" autocomplete="off" placeholder="请输入开始时间" lay-verify="required" name="startTime" id="startTime">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label layui-required">结束时间</label>
                            <div class="layui-input-block">
                                <input class="layui-input" autocomplete="off" placeholder="请输入结束时间" lay-verify="required" name="endTime" id="endTime">
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <label class="layui-form-label layui-required">团购说明</label>
                            <div class="layui-input-block">
                                <textarea class="layui-input" name="actiDesc" lay-verify="required" placeholder="请输入团购说明" style="height: 100px;"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="add" lay-submit="" id="submit">保存</button>
            </div>
        </form>
    </div>
</div>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
layui.use(['form','layer','laydate','layedit','upload'], function(){
    var form = layui.form,layer = layui.layer,upload = layui.upload,textInit;
    layui.laydate.render({elem: '#startTime',theme: '#2f4554',type: 'date',trigger: 'click',min:minDate(),format:'yyyy-MM-dd'});
    layui.laydate.render({elem: '#endTime',theme: '#2f4554',type: 'date',trigger: 'click',min:minDate(),format:'yyyy-MM-dd'});
    $.post(geturl()+'/cateringGoods/select?token='+sessionStorage.getItem("token"), JSON.stringify({status:0}), function (res) {
        for(var i in res.data) $('#goodsId').append('<option value="'+res.data[i].sysId + '" goodsName="'+res.data[i].goodsName + '" goodsPrice="'+res.data[i].goodsPrice + '">【'+res.data[i].goodsPrice+'】' + res.data[i].goodsName + '</option>');
        layui.form.render();
    }).done(function(){
        $.post('/cateringGroupActivities/select?token='+sessionStorage.getItem("token"), JSON.stringify({sysId:getQueryString("sysId")}), function (res) {
            for(var i in res.data){
                form.val("editForm", {
                    "goodsId": res.data[i].goodsId,
                    "actiName": res.data[i].actiName,
                    "actiPrice": res.data[i].actiPrice,
                    "groupSize": res.data[i].groupSize,
                    "startTime": res.data[i].startTime,
                    "endTime": res.data[i].endTime,
                    "actiDesc": res.data[i].actiDesc,
                });
                if(!isEmpty(res.data[i].goodsImg)) $("#agoodsImg").html('<a href="#" style="color:blue;" onclick="showpic(\''+res.data[i].goodsImg+'\',60,80)" title="预览">预览<i class="layui-icon">&#xe615;</i></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="cleardata(\'goodsImg\',\''+res.data[i].goodsImg+'\',\'0\')">清空<i class="layui-icon layui-icon-close"></i></a><br>');
                layui.form.render();
                textInit = JSON.stringify({ dataform: $("#edit").serializeArray() });
            }
        }, 'json');
    })
    //监听提交
    layui.form.on('submit(add)', function(data){
        data.field.sysId = getQueryString("sysId")
        var text = JSON.stringify({ dataform: $("#edit").serializeArray() });
        if(textInit == text) {
            layui.use('layer',function(){
                layer.msg("没有更改无需提交!",{icon:5,time:1000});
            })
        }else layuiPost('/cateringGroupActivities/update?token='+sessionStorage.getItem("token"),data.field,parent.layer.getFrameIndex(window.name));
        return false;
    });
});
</script>
</body>
</html>